package com.example.demo.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.List;

import com.example.demo.controller.Result;
import com.example.demo.sys.mapper.AdsMapper;
import com.example.demo.sys.entity.Ads;

import org.springframework.web.bind.annotation.RestController;
import com.example.demo.common.tools.BaseController;

/**
 * <p>
    *  前端控制器 chrimer
    * </p>
 *
 * @author chrimer
 * @since 2020-07-01
 */
@RestController
@RequestMapping("/sys/ads")
public class AdsController extends BaseController {
    @Autowired
    private AdsMapper adsMapper;

    @RequestMapping(method= RequestMethod.POST,value="/page")
    public Result page(
        Integer pageNum,
        Integer pageSize,
        String ads) {
        Result result = new Result();
        Page<Ads> page = new Page<Ads>(pageNum, pageSize);
        Ads parms = new Ads();
        QueryWrapper<Ads> warpper = new QueryWrapper<Ads>(parms);
        if(ads !=null && !"".equals(ads))
            warpper.eq("ads", ads);
        result.setData(adsMapper.selectPage(page, warpper));
        return result;
    }
    @RequestMapping(method= RequestMethod.POST,value="/save")
    public Result save(@RequestBody Ads entity) {
        Result result = new Result();
        if (entity.getId() == null||"".equals(entity.getId())) {
                adsMapper.insert(entity);
        } else {
    adsMapper.updateById(entity);
        }
        return result;
    }

    @RequestMapping(method= RequestMethod.DELETE,value="/delete")
    public Result delete( String id) {
        Result result = new Result();
        adsMapper.deleteById(id);
        return result;
    }

    //查看课程视频信息树
    @RequestMapping(method= RequestMethod.POST,value="/selectads")
    public Result selectads() {
        Result result = new Result();
        Ads parms = new Ads();
        QueryWrapper<Ads> warpper = new QueryWrapper<Ads>(parms);
        result.setData(adsMapper.selectList(warpper));
        return result;
    }

}
